import {User} from '@/api/user/type'
function getUserList() : User[] {
  return [
    {
      id: 1,
      username: 'admin',
      password: 'ABCabc123',
      avatar: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',
      name: 'ADMIN',
      roles:['管理员'],
      routes: ['home'],
      token: "admin",
    },
    {
      id: 2,
      username: 'ls',
      password: 'ABCabc123',
      avatar: 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png',
      name: '李四',
      roles:['用户'],
      routes: ['home'],
      token: "ls",
    },
  ]
}


export default [
  {
    url: '/api/user/login',
    method: 'post',
    response: ({body}) => {
      const {username,password} = body;

      const checkUser = getUserList().find(item => item.username === username && item.password === password);
      if(!checkUser){
        return {
          code: 401,
          message: '用户名或密码错误',
        }
      }
      return {
        code: 200,
        data: {'token':checkUser.token}
      }
    },
  },
  {
    url: '/api/user/info',
    method: 'get',
    response: (request) => {
      const token = request.headers.token;
      console.log(token)
      const checkUser = getUserList().find(item => item.token === token);
      if(!checkUser){
        return {
          code: 201,
          message: 'token失效,请重新登录',
        }
      }
      return {
        code: 200,
        data: {...checkUser}
      }
    },
  }

]
